<?php n_mod('datatables')->loadDataTables();?>
<link rel="stylesheet" type="text/css" href="<?=n_css('nlog','nlog')?>">
<div class="wrapper">
<div class="form-group search_nlog">
	<form method="get" action="<?=n_url('nlog', 'error')?>">
		<input readonly class="n-calendar n-col-2 search_nlog_input" name="time" type="text" value=<?=isset($data['time'])?$data['time']:date('Y-m-d')?>>
		<div class="n-col-2">
			<input name="plugin" type="text" <?php if(isset($data['plugin'])&& $param['plugin'] != '') echo "value=".$data['plugin']; else echo "placeholder=插件名称"?>>
		</div>
		<div class="n-col-2">
			<button class="a-button-blue">查询</button>
		</div>
		<div class="n-col-2">
			<!--<input name="type" type="text" placeholder="日志类型"/>-->
		</div>
		<div class="n-col-2">
			<!--<input name="scode" type="text" placeholder="scode"/>-->
		</div>
		<div class="n-col-2">
			<!--<input name="utype" type="text" placeholder="自定义错误类型"/>-->
		</div>
	</form>
</div>
<div class="n-row">
<?php
	$nsite = n_api('nsite');
?>
<table id="search-error-table" class="a-table a-table-striped">
	<thead>
		<tr>
			<th>日志时间</th>
			<th>插件名称</th>
			<th>自定义错误类型</th>
			<th>错误内容</th>
		</tr>
	</thead>
	<tbody>
<?php foreach($data['data'] as $value):?>
	<tr id="<?=$value['_id']?>">
		<td><?=date('Y-m-d H:m:s',$value['time'])?></td>
		<td><?=$value['plugin']?></td>
		<td><?=$value['utype']?></td>
		<td><?=$value['content']?></td>
	</tr>
<?php endforeach;?>
	</tbody>
	<tfoot>
		<tr>
			<th>日志时间</th>
			<th>插件名称</th>
			<th>自定义错误类型</th>
			<th>错误内容</th>
		</tr>
	</tfoot>
</table>
</div>
<div class="n-paging"><?=$data['paging']?></div>
</div>

<script type="text/javascript">
var arr = new Array();
<?php 
	foreach($data['data'] as $key => $value) {
		echo "arr['$key'] = '". json_encode($value['content']) ."'; \n";
	}
?>

$(document).ready(function() {
	var table = $("#search-error-table").DataTable({
		"order": [[0, "desc"]]
	});

	$("#search-error-table tbody").on('click', 'td.details-control', function() {
		var tr = $(this).closest('tr');
		var row = table.row(tr);

		if ( row.child.isShown() ) {
			row.child.hide();
			tr.removeClass('shown');
		}
		else {
			row.child( arr[tr.attr('id')] ).show();
			tr.addClass('shown');
		}
	});

	$(".search_nlog button").click(function() {
		$(".search_nlog form").submit();
	})
});
</script>